package com.example.administrator.szb.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;

/**
 * Created by stone on 2018/1/30.
 */

public class SlideOnePageGallery  extends Gallery {

    public SlideOnePageGallery(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public SlideOnePageGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SlideOnePageGallery(Context context) {
        super(context);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                           float velocityY) {

        int kEvent;
        if (isScrollingLeft(e1, e2)) {
            kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
        } else {
            kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
        }
        onKeyDown(kEvent, null);

        if (this.getSelectedItemPosition() == 0) {// 实现后退功能
            //this.setSelection(CycleImageActivity.picture.length);
        }
        return false;

    }

    private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
        return e2.getX() > e1.getX();
    }

    /*@Override
    protected boolean getChildStaticTransformation(View child, Transformation t) {
        t.clear();
        child.setAlpha(0.5f);
        //t.setTransformationType(Transformation.TYPE_MATRIX);

        return true;
    }*/
}